import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:xmshop/app/services/screebAdapter.dart';

import '../controllers/register_step_one_controller.dart';
import '../../../../widget/logo.dart';
import '../../../../widget/passTextField.dart';
import '../../../../widget/passButton.dart';

class RegisterStepOneView extends GetView<RegisterStepOneController> {
  const RegisterStepOneView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: 0,
        title: const Text('手机快速注册'),
      ),
      body: ListView(
        padding: EdgeInsets.all(ScreenAdapter.width(40)),
        children: [
          const Logo(),
          // 输入手机号
          PassTextFiled(
            controller: controller.editingController,
            hintText: "请输入手机号",
            onChanged: (value) {
              controller.phonNum = value;
            },
          ),
          PassButton(
              text: "下一步",
              onPressed: () async {
                if (GetUtils.isPhoneNumber(controller.editingController.text) &&
                    controller.editingController.text.length == 11) {
                  var flag = await controller.sendCode();
                  if (flag) {
                    Get.toNamed("/register-step-two", arguments: {
                      "phonNum": controller.editingController.text
                    });
                  } else {
                    Get.snackbar("提示信息", "网络异常");
                  }
                } else {
                  Get.snackbar('提示信息', '手机号不正确');
                }
              })
        ],
      ),
    );
  }
}
